home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / WebYAM / TextMode.rexx < prev    next >
OS/2 REXX Batch file  |  2000-09-20  |  7KB  |  224 lines

  1. /*
  2. ** $VER: TextMode 1.5 (19.2.2000)
  3. ** © 1999-2000 by Jacob Laursen <laursen@myself.com>
  4. **
  5. ** Browse YAM folders from shell
  6. **
  7. ** Requirements: YAM 2.0
  8. **
  9. ** For "quoted printable" -> "8bit" conversion, please download
  10. ** comm/mail/YToolsNG.lha from Aminet and copy the file 'YTCunmime'
  11. ** to the YAM: directory, or correct the path below.
  12. **
  13. ** Changes since version 1.4: - Completed 'HELP STATUS'.
  14. **                            - File 'TextMode.folders' is no longer used.
  15. **                              Instead, YAM's own .folders file is parsed
  16. **
  17. ** Changes since version 1.3: - Added flags/status and header to LIST.
  18. **                            - Added 'HELP STATUS' for information on
  19. **                              message flags/status.
  20. **
  21. ** Changes since version 1.2: - LISTFOLDERS didn't like separator lines
  22. **                            - Added command HELP
  23. **                            - Error message when going to a non-existing
  24. **                              folder or message is now handled internally
  25. */
  26.  
  27. options results
  28. options failat 11
  29.  
  30. signal on break_d
  31.  
  32. /* Name of text file to save name of folders in (for speedup) */
  33. FoldersFile = 'YAM:Rexx/TextMode.folders'
  34.  
  35. /* YAM executable path */
  36. YAMPath     = 'YAM:YAM'
  37.  
  38. /* YTCunmime executable path */
  39. UMPath      = 'YAM:YTCunmime'
  40.  
  41. /* YAM folders file */
  42. YAMFolders  = 'YAM:.folders'
  43.  
  44. /* No user-serviceable parts below... */
  45.  
  46. if ~show('P','YAM') then do
  47.   writech(stdout,'Loading YAM')
  48.   address command 'run <>nil: ' || YAMPath || ' HIDE'
  49.  
  50.   do while ~show('P','YAM')
  51.     writech(stdout,'.')
  52.     call delay(100)
  53.   end
  54.   writech(stdout,'0d'x)
  55. end
  56.  
  57. address 'YAM'
  58.  
  59. say 'Welcome to the world of Yet Another Mailer.'
  60. say 'CLI-interface by Jacob Laursen'
  61. say ''
  62. call Help
  63. say ''
  64.  
  65. /* Why doesn't ARexx have a GOTO command? */
  66.  
  67. FirstRun = 1
  68. break_c:
  69. signal on break_c
  70. if FirstRun = 0 then say '*** Break'
  71. else FirstRun = 0
  72.  
  73. /* Main loop */
  74.  
  75. do while (option ~= 'QUIT' & option ~= 'EXIT')
  76.  
  77.   FOLDERINFO STEM fi.
  78.   call WRITECH(STDOUT,fi.NUMBER || '.' || fi.NAME || '> ')
  79.   option = upper(READLN(STDIN))
  80.  
  81.   /* Commands... */
  82.  
  83.   if (word(option,1) = 'FOLDER' | word(option,1) = 'GOTOFOLDER') then do
  84.     SETFOLDER word(option,2)
  85.     if RC = 10 then say 'This folder does not exist. Please update folder list with `LISTFOLDERS UPDATE'''
  86.   end
  87.  
  88.   if word(option,1) = 'GOTO' then do
  89.     if words(option) = 2 then call GotoMail(word(option,2))
  90.   end
  91.  
  92.   if word(option,1) = 'READ' then do
  93.     if words(option) = 2 then RC = GotoMail(word(option,2))
  94.     else RC = 0
  95.     if RC = 10 then break
  96.     MAILEXPORT 'T:YAM-TextMode.tmp'
  97.     if exists(UMPath) = 1 then address command UMPath || ' MAIL=T:YAM-TextMode.tmp'
  98.     address command 'Type T:YAM-TextMode.tmp'
  99.     address command 'Delete >NIL: T:YAM-TextMode.tmp'
  100.   end
  101.  
  102.   if option = 'LIST' then do
  103.     FOLDERINFO STEM fi.
  104.     say 'No. Name                    Subject              Date     Time       Size Flags'
  105.     say '--- ----------------------- -------------------- -------- -------- ------ -----'
  106.     do loop = 0 to fi.TOTAL-1
  107.       SETMAIL loop
  108.       MAILINFO STEM sel.
  109.       if index(sel.FROM,'<') ~= 0 then email = left(sel.FROM,index(sel.FROM,'<')-2)
  110.       else email = sel.FROM
  111.       say left(sel.INDEX,4,' ') || left(email,23,' ') || ' ' || left(sel.SUBJECT,20,' ') || ' ' || sel.DATE || ' ' || WriteAlignRight(sel.SIZE,6) || ' ' || left(sel.FLAGS,4) || sel.STATUS
  112.     end
  113.     say
  114.   end
  115.  
  116.   if word(option,1) = 'LISTFOLDERS' then do
  117.     if (word(option,2) = 'UPDATE' | ~exists(YAMFolders)) then do
  118.       say 'No. Folder                         Total  Unr.   New'
  119.       say '--- ------------------------------ ----- ----- -----'
  120.       currentfolder = fi.NUMBER
  121.       i = 0
  122.       do forever
  123.         SETFOLDER i
  124.         if RC = 10 then do
  125.           SETFOLDER i+1
  126.           if RC = 10 then leave
  127.           /* Workaround for separator lines. Two in a row still breaks this routine */
  128.           else say '--- ------------------------------ ----- ----- -----'
  129.           i = i + 1
  130.           iterate
  131.         end
  132.         FOLDERINFO STEM cfi.
  133.         say left(cfi.NUMBER,4,' ') || left(cfi.NAME,30,' ') || ' ' || WriteAlignRight(cfi.TOTAL,5) || ' ' || WriteAlignRight(cfi.UNREAD,5) || ' ' || WriteAlignRight(cfi.NEW,5)
  134.         i = i + 1
  135.       end
  136.       SETFOLDER currentfolder
  137.     end
  138.     else do
  139.       say 'No. Folder                        '
  140.       say '--- ------------------------------'
  141.       call open(fh, YAMFolders, 'R')
  142.       i = 0
  143.       do while ~eof(fh)
  144.         line = readln(fh)
  145.         if word(line, 1) = '@FOLDER' then do
  146.           say left(i, 4, ' ') || right(line,length(line)-8)
  147.           i = i + 1
  148.         end
  149.         else if word(line, 1) = '@SEPARATOR' then do
  150.           if length(line) > 11 then do
  151.             full = '------------------------------'
  152.             sname = right(line,length(line)-11)
  153.             sep = '--- ' || left(full, trunc((30-length(sname))/2)) || sname || left(full, trunc((30-length(sname))/2))
  154.             if length(sname)/2 ~= trunc(length(sname)/2) then sep = sep || '-'
  155.             say sep
  156.           end
  157.           else say '--- ------------------------------'
  158.           i = i + 1
  159.         end
  160.       end
  161.       call close(fh)
  162.     end
  163.     say
  164.   end
  165.  
  166.   if option = 'GET' then MAILCHECK
  167.  
  168.   if word(option,1) = 'HELP' then do
  169.     if words(option) = 1 then call Help
  170.     else if word(option,2) = 'STATUS' then do
  171.       say 'MARCX:   M = Multiple recipients'
  172.       say '         A = Attachments'
  173.       say '         R = Report'
  174.       say '         C = Encrypted'
  175.       say '         X = N, O, U, R, F, S, W, H or E'
  176.       say '             N = New'
  177.       say '             O = Old'
  178.       say '             U = Unread'
  179.       say '             R = Replied'
  180.       say '             F = Forwarded'
  181.       say '             S = Sent'
  182.       say '             W = WaitSend'
  183.       say '             H = Hold'
  184.       say '             E = Error'
  185.     end
  186.   end
  187.  
  188. end
  189.  
  190. exit
  191.  
  192. WriteAlignRight: PROCEDURE
  193. parse arg OldString, Length
  194.  
  195.   NewString = copies(' ',Length-length(OldString)) || OldString
  196.  
  197. return NewString
  198.  
  199. GotoMail: PROCEDURE
  200. parse arg num
  201.  
  202.   SETMAIL num
  203.   if RC ~= 10 then return 0
  204.   else say 'This mail does not exist. Please re-read index with `LIST'''
  205.  
  206. return 10
  207.  
  208. Help: PROCEDURE
  209.  
  210.   say 'Commands:   QUIT or EXIT            Exit program'
  211.   say '            LISTFOLDERS [UPDATE]    List folders'
  212.   say '            GOTOFOLDER <folder-#>   Change current folder'
  213.   say '            LIST                    List messages in current folder'
  214.   say '            GOTO <message-#>        Change current message'
  215.   say '            READ [<message-#>]      Read current or selected message'
  216.   say '            GET                     Get new mail'
  217.   say '            HELP [STATUS]           Display this text or status info'
  218.  
  219. return
  220.  
  221. break_d:
  222.   say '*** Execution halted'
  223.   exit
  224.